package com.wangwei.mq.springboot;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangwei on 2019/11/15 0015.
 */
@RestController
public class SendController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping(value = "/send/mail",method = {RequestMethod.GET})
    public String send(){
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentType("text");
        Message message = new Message("小楼昨夜又东风，意难平！".getBytes(),messageProperties);

        rabbitTemplate.send("","mail", MessageBuilder.withBody("小楼昨夜又东风，意难平！".getBytes()).setContentType("text").build());
        return "SUCCESS";
    }
}
